package cn.aihongbo.test.shake.ui.page

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

/**
 * Created by ZhaoHongBo on 2025/11/4.
 * Copyright (c) 2025 ZHB. All rights reserved.
 */
class ShakeViewModel : ViewModel() {

    private val _doRun = MutableStateFlow("")
    val doRun = _doRun.asStateFlow()

    private val _showImage = MutableStateFlow<String?>(null)
    val showImage = _showImage.asStateFlow()

    var count = 0

    fun show() {
        viewModelScope.launch(Dispatchers.IO) {
            count++
            _doRun.emit("${count}=>>>摇一摇${System.currentTimeMillis()}")
        }
    }

    fun loadImage(localFile: String?) {
        viewModelScope.launch(Dispatchers.IO) {
            if (localFile?.isNotEmpty() == true) {
                _showImage.emit(localFile)
            }
        }
    }
}